import java.util.ArrayList;
import java.util.List;

public class Test4 {
    public static void main(String[] args) {
        String s = "SJ111aaJSI";
        char c = s.charAt(0);
//        System.out.println(s.toLowerCase());
//        StringBuffer sb = new StringBuffer();
//        sb.append('a');
//        sb.deleteCharAt(0);
//        char ch = 'a';
//        char ch1 = (char) (ch + 'A' - 'a');
//        System.out.println(ch1);
        letterCasePermutation("a1b2");
    }

    static List<String> ret;
    static StringBuffer sb;
    public static List<String> letterCasePermutation(String s) {
        ret = new ArrayList<>();
        sb = new StringBuffer();
        char[] arr = s.toLowerCase().toCharArray();
        dfs(arr, 0);
        return ret;
    }
    public static void dfs(char[] arr, int pos) {
        if(sb.length() == arr.length) {
            ret.add(sb.toString());
            return;
        }

        char ch = arr[pos];
        if(arr[pos] >= 'a' && arr[pos] <= 'z') {
            sb.append(ch);
            dfs(arr, pos + 1);
            sb.deleteCharAt(sb.length() - 1);

            sb.append((char) (ch + 'A' - 'a'));
            dfs(arr, pos + 1);
            sb.deleteCharAt(sb.length() - 1);
        }else {
            sb.append(ch);
            dfs(arr, pos + 1);
            sb.deleteCharAt(sb.length() - 1);
        }
    }
}
